using UnityEngine;
using UnityEngine.UI;

using System;
using System.Collections;

using RestSharp;
using PuSuoPai;

public class UILogin : MonoBehaviour
{
	public static Player CurPlayer = null;

	public InputField InputAccount, InputPassward;

	// Use this for initialization
	void Start ()
	{

	}

	// Update is called once per frame
	void Update ()
	{

	}

	public void Login()
	{
		if (InputAccount == null || InputPassward == null)
			return;

		if (string.IsNullOrEmpty(InputAccount.text) || string.IsNullOrEmpty(InputPassward.text))
			return;


		var request = new RestRequest("Login", Method.POST);
		request.AddParameter("Name", InputAccount.text); // adds to POST or URL querystring based on Method
		request.AddParameter("Passward", InputPassward.text); 
		IRestResponse<Player> player = UINetworkMgr.Instance.WebClient.Execute<Player>(request);

		CurPlayer = player.Data;

		if (CurPlayer != null && !string.IsNullOrEmpty(CurPlayer.Id))
		{
			UILoading.Instance.LoadScene("Lobby", false);
		}
	}

	public void Create()
	{
	}
}

